﻿<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="B05_FixMoneyLimit.aspx.vb" Inherits="B05_FixMoneyLimit" %>

<%@ Register Assembly="ISNet.WebUI.WebInput" Namespace="ISNet.WebUI.WebControls" TagPrefix="ISWebInput" %>

<%@ Register Assembly="ISNet.WebUI.WebTreeView" Namespace="ISNet.WebUI.WebTreeView" TagPrefix="ISWebTreeView" %>

<%@ Register Assembly="ISNet.WebUI.WebGrid" Namespace="ISNet.WebUI.WebGrid" TagPrefix="ISWebGrid" %>

<%@ Register Assembly="ISNet.WebUI.WebCombo" Namespace="ISNet.WebUI.WebCombo" TagPrefix="ISWebCombo" %>

<%@ Register Assembly="ISNet.WebUI.WebDesktop" Namespace="ISNet.WebUI.WebDesktop" TagPrefix="ISWebDesktop" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <link href="js/magicsuggest-1.2.6.css" rel="stylesheet" />
    <script src="js/magicsuggest-1.2.6.js"></script>
    <script src="script/packed.js"></script>
    <script src="script/tinybox.js"></script>
    <link href="script/style.css" rel="stylesheet" />
    <script type="text/javascript" src="js/JSON.js"></script>
    <script type="text/javascript">
        function openJS() { alert('loaded') }
        function closeJS() { doupdate() }
        function closeJS2() { doupdate() }
        function doupdate() {
            var grid = ISGetObject("WebGrid1");
            grid.ClearSelectedObject();
            grid.RootTable.UpdateUI();
            grid.RefreshAll();

        }
        function popupattach1() {

            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();



            //get the key value of selected row.
            var key = row.KeyValue;

            TINY.box.show({ iframe: 'neatupload.aspx?BDID=' + key, boxid: 'frameless', width: 540, height: 450, fixed: false, maskid: 'lightmask', maskopacity: 40, closejs: function () { closeJS() } });




        }
        function popupattach2() {

            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();
            var key = row.KeyValue;

            //get the key value of selected row.
            TINY.box.show({ iframe: 'AttachmentListPopup.aspx?BDID=' + key, boxid: 'frameless', width: 350, height: 250, fixed: false, maskid: 'lightmask', maskopacity: 40, closejs: function () { closeJS2() } })
        }
    </script>

    <script>
        function WebGrid1_OnAfterExitEditMode(controlId, tblName, editObject) {


            var WebGrid1 = ISGetObject(controlId);
            //var rootTable = WebGrid1.RootTable;
            var cell = wgGetCellByElement(editObject.cellElement);
            var colName = cell.Name;
            var row = cell.Row;
            var htmlRow = row.GetElement();
            //alert(colName);
            if (colName == "money") {
                var num1 = parseFloat((wgGetCellByPosition(htmlRow, 5).innerText).replace(/\,/g, ''));
                if (num1 > 0) {
                    row.GetCells().GetNamedItem("percen").SetText("0", true);
                }
            } else if (colName == "percen") {
                var num1 = parseFloat((wgGetCellByPosition(htmlRow, 4).innerText).replace(/\,/g, ''));
                if (num1 > 0) {
                    row.GetCells().GetNamedItem("money").SetText("0", true);
                }
            }



        }
        function WebGrid1_OnRowContextMenu(controlId, rowType, rowElement, menuObject) {
            menuObject.Items[0].Hide();

            return false;
        }
        function ActivityTypeCombo_OnAfterItemSelected(controlId) {
            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();

            var code_combo = ISGetObject("ProductCombo");
            code_combo.ClearSelection();
            code_combo.Value = "";
            code_combo.SetTextBoxValue("");
            row.GetCells().GetNamedItem("Product").SetText("", true);



            var code_combo = ISGetObject("ActivityTypeCombo");
            var comborow = code_combo.GetSelectedRow();
            var code_text = comborow.cells[2].innerText;


            //var htmlRow = row.GetElement();
            var num1 = code_text.replace(/\,/g, '');

            //alert(num1);
            row.GetCells().GetNamedItem("PricePerUnit2").SetForceNoEdit(false);
            row.GetCells().GetNamedItem("PricePerUnit2").SetText(num1, true);
            row.GetCells().GetNamedItem("PricePerUnit2").SetForceNoEdit(true);
        }


        function OnRowSelect(controlId, tblName, rowIndex, rowElm) {


            var grid = ISGetObject("WebGrid1");

            if (grid.GetSelectedObject().GetRowObject().Type == "NewRow") {
                var row = grid.GetSelectedObject().GetRowObject();

                row.GetCells().GetNamedItem("budget").SetText("0", true);
                row.GetCells().GetNamedItem("budget").SetForceNoEdit(true);
            }
            var ar = grid.GetSelectedObject().GetRowElement();
            //alert(ar.IsAddNewRow);
            if (ar.IsAddNewRow) { }
            else {
                var row = grid.GetSelectedObject().GetRowObject();
                // row.GetCells().GetNamedItem("Amount").SetForceNoEdit(true);
                //  row.GetCells().GetNamedItem("Attachment").SetForceNoEdit(true);
                try {
                    var combo = ISGetObject("FundCenterCombo");
                    var Val = row.GetCells().GetNamedItem("FundCenter").Value

                    combo.SetValue(Val);
                } catch (err) { }
            }

        }
        function WebGrid1_OnRowValidate(rowObject) {
            // retrieves WebGrid's object
            var grid = ISGetObject("WebGrid1");
            //alert("xxx");
            // access WebGrid's RootTable
            var rootTable = grid.RootTable;

            var row = rootTable.ToRowObject(rowObject); // convert the rowObject (HTMLElement) to WebGridRow object
            var htmlRow = row.GetElement();
            var cells = row.GetCells(); // get collection of WebGridCell
            var error = 0;
            var err_text = "กรุณาตรวจสอบ \n"


            if (grid.GetSelectedObject().GetRowObject().Type == "NewRow") {
                // alert("ddd"); return false;
                var data;
                data = wgGetCellByPosition(htmlRow, 1).innerText;
                if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                    err_text = err_text + "\n   ● FundCenter";
                    error = error + 1;
                }

                data = wgGetCellByPosition(htmlRow, 2).innerText;
                if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                    err_text = err_text + "\n   ● รายการ";
                    error = error + 1;
                }

                data = wgGetCellByPosition(htmlRow, 3).innerText;
                if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                    err_text = err_text + "\n   ● ผลิตภัณฑ์";
                    error = error + 1;
                }

                data = wgGetCellByPosition(htmlRow, 5).innerText;
                var num3 = parseFloat((wgGetCellByPosition(htmlRow, 5).innerText).replace(/\,/g, ''));
                data2 = wgGetCellByPosition(htmlRow, 4).innerText;
                var num32 = parseFloat((wgGetCellByPosition(htmlRow, 4).innerText).replace(/\,/g, ''));

                if ((num3 <= 0 || data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") && (num32 <= 0 || data2.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "")) {
                    err_text = err_text + "\n   ● % ในการกระจาย หรือ วงเงิน";
                    error = error + 1;
                }



            }
            else {
            }

            // alert("2");
            if (error == 0) {
                var grid = ISGetObject("WebGrid1");
                var percen = 0;
                var totalRows = grid.TotalRows;

                for (var i = 0; i < totalRows ; i++) {
                    var row2 = grid.RootTable.GetRow(i);
                    var rcell2 = row2.GetCells().GetNamedItem("percen");

                    if (rcell2 != "NaN") {
                        if (rcell2.Value > 0) {
                            percen += parseFloat(rcell2.Value.replace(/\,/g, ''));
                            // alert(rcell2.Value + "/" + percen + "/" + numNow);
                        }
                    }
                }
                data = wgGetCellByPosition(htmlRow, 4).innerText;
                var numNow = parseFloat((wgGetCellByPosition(htmlRow, 4).innerText).replace(/\,/g, ''));
                if (grid.GetSelectedObject().GetRowObject().Type == "NewRow") {
                    percen = percen + numNow;
                }
                if (percen > 100) {
                    alert(" ● เปอร์เซ็นต์เกิน 100 ไม่ได้");
                    return false;
                } else {
                    return true;
                }
                //return true;
            } else {
                alert(err_text);
                return false;
            }

        }

        function WebGrid1_OnEditKeyDown(controlId) {
            //alert(event.keyCode);
            var grid = ISGetObject("WebGrid1");

            var totalRows = grid.TotalRows;
            var totalCells = grid.TotalCells;
            var curRow = grid.GetSelectedObject().rowIndex;
            var curCell = grid.GetActiveEditCell().cellIndex;

            // if enter key
            if (event.keyCode == 13) {
                if (totalRows >= 2) {
                    if (curRow < totalRows - 1) {
                        keyDown(curRow, curRow + 1, curCell - 1);
                    }
                }
                //grid.ExitEdit(1,0,0);
                //return false;
                //var ar = grid.GetSelectedObject().GetRowElement();

                //if (ar.IsAddNewRow) {
                //    ar.commit();
                //}
                //else {
                //    event.keyCode = 40;
                //    keyDown(curRow, curRow + 1, curCell - 1);
                //}
            }

                // if up arrow
            else if (event.keyCode == 38 && grid.GetSelectedObject().GetRowObject().Type != "NewRow") {
                if (totalRows >= 2) {
                    if (curRow > 0) {
                        keyDown(curRow, curRow - 1, curCell - 1);
                    }
                }
            }

                // if down arrow key
            else if (event.keyCode == 40 && grid.GetSelectedObject().GetRowObject().Type != "NewRow") {
                if (totalRows >= 2) {
                    if (curRow < totalRows - 1) {
                        keyDown(curRow, curRow + 1, curCell - 1);
                    }
                }
            }
                // if left arrow key
            else if (event.keyCode == 37) {

                if (curCell > 1) {
                    //jq(document).trigger(jq.Event('keydown', { keyCode: 9, shiftKey: true }));
                    //var press = jQuery.Event("keydown");
                    //press.shiftKey = false;
                    //press.which = 9;
                    //jq("WebGrid1").trigger(press);
                    //alert("x");
                    //return;
                    keyDown2(curRow, curCell - 2);

                }
            }
                // if right arrow key
            else if (event.keyCode == 39) {
                //if (curCell < totalCells - 1) {
                event.keyCode = 9;
                return true;
                //}
            }


        }

        function keyDown(curRow, nextRow, cell) {
            var grid = ISGetObject("WebGrid1");
            var nextRowEl = grid.RootTable.GetRow(nextRow);
            var curRowEl = grid.RootTable.GetRow(curRow);
            var cell1 = nextRowEl.GetCell(cell);
            var cell2 = curRowEl.GetCell(cell);
            grid.ExitEdit(1, 0, 0);
            grid.SetFocus();

            cell2.Select(true);

            nextRowEl.Select();

            cell1.ActivateEdit();
        }
        function keyDown2(curRow, cell) {
            var grid = ISGetObject("WebGrid1");

            var selectedObject = grid.GetSelectedObject(); // return object of type SelectedObject
            var selectedRow = selectedObject.ToRowObject();
            var cell1 = selectedRow.GetCell(cell);
            grid.SetFocus();
            cell1.Select(true);
            cell1.ActivateEdit();

        }

        function triggerKeyEvents(field, keyCode, shiftKey, ctrlKey) {

            field = $(field);

            shiftKey = Boolean(shiftKey);

            ctrlKey = Boolean(ctrlKey);


            field.simulate("keydown", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });

            field.simulate("keypress", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });


            if (field.is(HTML5_TEXT_INPUT_FIELD_SELECTOR)) {

                applyKeyCodeToValue(field, keyCode);

            }


            field.simulate("keyup", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });

        }

        function SaveScrollPosition(gridId, action) {
            // collecting the last position
            // of the vertical scrollbar
            // by obtaining the scrollTop property
            var grid = ISGetObject(gridId);
            // obtain the scrollTop and scrollLeft property 
            // of the vertical scrollbar and horizontal scrollbar
            var vl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollTop + "";
            var hl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollLeft + "";
            // only send the scrollTop property
            // of the server if the action performed
            // by the grid OTFPB is 'Refresh'

            //if (action == "Refresh") {
            // sending over the scrollTop and scrollLeft property
            // to the server by using AddInput method
            grid.AddInput("scrollTopPos", vl);
            grid.AddInput("scrollLeftPos", hl);
            //}

            return true;
        }

        function ApplyLatestScroll(gridId, y, x) {
            // set back the previous scrollTop and scrollLeft property or
            // vertical and horizontal scroll position with 
            // the parameter sent from the server side
            var grid = ISGetObject(gridId);
            // manually configure the vertical and horizontal scroll position
            grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollTop = y;
            grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollLeft = x;

            var cellEl = grid.GetActiveEditCell().ToCellObject();
            grid.SetFocus();
            cellEl.ActivateEdit();
            return true;
        }



        // This function is invoked when the custom request is about to be made.
        function wgPrepareCustomAction(grid, xmlr, name) {
            grid.SetStatus1("Processing...");
            return true;
        }
        var exp = '0';
        function WebTreeView3_Expand() {
            exp = '1';
            var combo = ISGetObject("WebCombo3");
            combo.SetFocus();
            combo.ShowDropDown();
        }
        function WebTreeView3_Collapse() {
            exp = '1';
            var combo = ISGetObject("WebCombo3");
            combo.SetFocus();
            combo.ShowDropDown();
        }
        function WebCombo3_Hide() {
            if (exp == '1') {
                exp = '0';
                var combo = ISGetObject("WebCombo3");
                combo.SetFocus();
                combo.ShowDropDown();
            }
        }

        function WebGrid1_OnEnterEditMode(controlId, tblName, editObject) {

        }
        function checkMoney() {
            if (confirm('กรุณายืนยันการกระจายวงเงิน') == false) {
                return false
            }
            var money = document.getElementById("<%= TextBox1.ClientID %>").value;
            if (money > 0) { return true; }
            else {
                alert("กรุณากรอกวงเงินรวม"); return false;
            }

        }
        function CustomRequestDel() {
            if (confirm('กรุณายืนยันการลบข้อมูล') == false) {
                return false
            }
            var grid = ISGetObject("WebGrid1");
            var table = grid.GetRootTable();
            var checkedRows = table.GetCheckedRows();

            if (checkedRows.length == 0) {
                alert("Please check an item.");
                setTimeout(function () { grid.SetFocus(); }, 10);
            }
            else {

                grid.AddInput("type", "2");
                grid.SendCustomRequest();

            }

            event.cancelBubble = true;
            event.returnValue = false;
        }

        var gridedit = 0;

        function WebGrid1_OnKeyDown(controlId) {
            var grid = ISGetObject("WebGrid1");

            // if enter key
            if (event.keyCode == 27) {
                if (gridedit == 1) {
                    grid.ExitEditMode(true);
                    gridedit = 0;
                }
                else {
                    return false;
                }
            }
        }

        function WebGrid1_OnEnterEditMode(controlId) {
            gridedit = 1;
        }
    </script>
    <style>
        .WC4-DD-N {
            height: 0px;
        }

        .WC4-DD-A {
            height: 0px;
        }
    </style>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="margin-left: 10px; padding: 10px 10px 10px 10px;">
        <div style="float: left; width: 97%; border: solid; border-color: #a0a0a0; border-width: 1px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; text-align: right; padding: 5px 5px 5px 5px;">
            <div style="text-align: right; margin-top: 5px;">
                <div align="left" style="width: 600px; float: left">
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </div>

                ปี&nbsp;
            <asp:TextBox ID="PlanYearsTxt" runat="server" Width="50px" Enabled="false" Style="text-align: center;"></asp:TextBox>
                &nbsp;&nbsp;&nbsp;&nbsp;
            Version&nbsp;
            <asp:TextBox ID="VersionTxt" Text="1" runat="server" Width="30px" Style="text-align: center" Enabled="false"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         
            </div>
        </div>
        <div>
            <div id="div1" runat="server" style="float: left; width: 40%; border: solid; border-color: #a0a0a0; border-width: 1px; margin-right: 10px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; height: 92px;">

                <div style="padding-bottom: 5px;"><strong>&nbsp;FundCenter</strong></div>


                <asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1" Height="30px" Width="100%" EnableTheming="True">
                    <asp:TabPanel ID="TabPanel1" runat="server" HeaderText="ตั้งแต่ ถึง">
                        <ContentTemplate>
                            <table>
                                <tr>
                                    <td>ตั้งแต่</td>
                                    <td>
                                        <ISWebCombo:WebCombo ID="WebCombo1" Width="200px" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="FundCenterCode" Height="20px" AdditionalSearchFields="FundCenterCode" AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ FundCenter" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="FundCenterCode" Name="FundCenterCode" HeaderText="รหัส FundCenter" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>
                                        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByUser" TypeName="BasicDataTableAdapters.FCTR_Child2TableAdapter">
                                            <SelectParameters>
                                                <asp:SessionParameter Name="username" SessionField="users" Type="String" />
                                            </SelectParameters>
                                        </asp:ObjectDataSource>
                                    </td>
                                    <td>ถึง</td>
                                    <td>
                                        <ISWebCombo:WebCombo ID="WebCombo2" Width="200px" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="FundCenterCode" Height="20px" AdditionalSearchFields="FundCenterCode" AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ FundCenter" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="FundCenterCode" Name="FundCenterCode" HeaderText="รหัส FundCenter" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>
                                        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByUser" TypeName="BasicDataTableAdapters.FCTR_Child2TableAdapter">
                                            <SelectParameters>
                                                <asp:SessionParameter Name="username" SessionField="users" Type="String" />
                                            </SelectParameters>
                                        </asp:ObjectDataSource>
                                    </td>
                                </tr>
                            </table>

                        </ContentTemplate>
                    </asp:TabPanel>
                    <asp:TabPanel ID="TabPanel2" runat="server" HeaderText="เลือกเอง">
                        <ContentTemplate>
                            <div style="margin-left: 30px; color: #a0a0a0; font-size: 11px;">
                                <ISWebCombo:WebCombo ID="WebCombo3" runat="server" UseDefaultStyle="True" Width="350px" DataTextField="pathname" DataValueField="Fundcenter_FundcenterCode" AllowWildCardSearch="true" DropDownRows="100000">
                                    <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false">
                                    </LayoutSettings>                                    
                                </ISWebCombo:WebCombo>
                                &nbsp;(รวมหน่วยงานใต้สังกัด)
                            </div>
                        </ContentTemplate>
                    </asp:TabPanel>
                </asp:TabContainer>
            </div>
            <div id="div2" runat="server" style="float: right; width: 55%; border: solid; border-color: #a0a0a0; border-width: 1px; margin-right: 30px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; height: 92px;">
                &nbsp;
                <strong>Commitment Item</strong>
                <asp:TabContainer ID="TabContainer2" runat="server" ActiveTabIndex="0" Height="30px" Width="98%" EnableTheming="True">
                    <asp:TabPanel ID="TabPanel3" runat="server" HeaderText="ตั้งแต่ ถึง">
                        <ContentTemplate>
                            <table>
                                <tr>
                                    <td>ตั้งแต่</td>
                                    <td>
                                        <ISWebCombo:WebCombo ID="WebCombo4" Width="200px" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="CmmtCode" Height="20px" OnInitializeDataSource="WebCombo3_InitializeDataSource" AdditionalSearchFields="CmmtCode" AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ CommitmentItem" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="CmmtCode" Name="CmmtCode" HeaderText="รหัส CommitmentItem" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>

                                    </td>
                                    <td>ถึง</td>
                                    <td>
                                        <ISWebCombo:WebCombo ID="WebCombo5" Width="200px" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="CmmtCode" Height="20px" OnInitializeDataSource="WebCombo4_InitializeDataSource" AdditionalSearchFields="CmmtCode" AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ CommitmentItem" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="CmmtCode" Name="CmmtCode" HeaderText="รหัส CommitmentItem" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>

                                    </td>
                                </tr>
                            </table>

                        </ContentTemplate>
                    </asp:TabPanel>
                    <asp:TabPanel ID="TabPanel4" runat="server" HeaderText="เลือกเอง">
                        <ContentTemplate>
                            <div style="margin-left: 10px; color: gray; font-size: 11px;">
                                <asp:HiddenField runat="server" ID="hdf2" />
                                <asp:ListBox ID="ms9" runat="server" Width="95%" SelectionMode="Multiple"></asp:ListBox>
                            </div>
                        </ContentTemplate>
                    </asp:TabPanel>
                </asp:TabContainer>
                <script type="text/javascript">
                    $(document).ready(function () {
                        var ms10 = $('#<%= ms9.ClientID%>').magicSuggest({
                        });
                        clickedx = function () {
                            $("#<%= hdf2.ClientId %>").val(ms10.getValue());
                        }
                    });
                </script>
            </div>
            <br />
            <div style="float: left; width: 97%; border: solid; border-color: #a0a0a0; border-width: 1px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; text-align: right; padding: 5px 5px 5px 5px;">
                <div style="text-align: right; margin-top: 5px;">

                    <asp:Label ID="Label2" runat="server" Text="วงเงินรวม"></asp:Label>
                    <asp:TextBox ID="TextBox1" runat="server" Width="100px" Style="text-align: center;"></asp:TextBox>
                    <asp:Label ID="Label3" runat="server" Text="บาท"></asp:Label>&nbsp;&nbsp;
  <asp:Label ID="Label4" runat="server" Text="เทียบกับที่ตั้งไว้"></asp:Label>



                    &nbsp;&nbsp;&nbsp;&nbsp;
           
            <a href="#" title="เลือกหน่วยงานและโครงการที่ต้องการ จากนั้นคลิกที่ปุ่มนี้เพื่อทำการค้นหา">
                <asp:ImageButton ID="SearhBtn" runat="server" ImageUrl="Icons/search.jpg" OnClientClick="clickedx()" /></a>
                    &nbsp;&nbsp;<a href="#" title="เลือกรายการที่ต้องการ จากนั้นคลิกปุ่มนี้เพิ่อทำการลบรายการ"><asp:ImageButton ID="delete_btn" runat="server" ImageUrl="Icons/delete.jpg" OnClientClick="CustomRequestDel(); return false" /></a>
                    &nbsp;&nbsp;<asp:ImageButton ID="divide" runat="server" ImageUrl="~/Images/planIc/icon1.png" OnClientClick="return checkMoney();" />
                    &nbsp;
                </div>
            </div>
            <div style="float: left; width: 97%; border: solid; border-color: #a0a0a0; border-width: 1px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; padding: 5px 5px 5px 5px;">

                <div style="padding-bottom: 5px;"><strong>รายการงบประมาณ</strong></div>


                <ISWebGrid:WebGrid ID="WebGrid1" runat="server" UseDefaultStyle="True" Width="100%" OnAddRow="WebGrid1_AddRow" OnUpdateRow="WebGrid1_UpdateRow" DefaultStyleMode="Silver" OnInitializePostBack="WebGrid1_InitializePostBack" Height="250px" OnInitializeRow="WebGrid1_InitializeRow">
                    <LayoutSettings AllowAddNew="Yes" EditOnClick="True" AllowColumnMove="No"
                        AllowEdit="Yes" AllowDelete="Yes" AllowSorting="Yes" ColumnFooters="Yes" NewRowLostFocusAction="AlwaysUpdate"
                        ResetNewRowValuesOnError="False" InProgressUIBehavior="ChangeCursorToHourGlass"
                        AlwaysShowHelpButton="false" PagingMode="ClassicPaging" PagingSize="10" ColumnFooterAggregateMode="CalculateAllData"
                        VirtualLoadMode="LargeData" AllowGrouping="Yes" VirtualPageSize="10" PagingLoadMode="Automatic">
                        <RowStyle Font-Names="Tahoma" Font-Size="9" CustomRules="overflow: hidden;" />
                        <AlternatingRowStyle Font-Names="Tahoma" Font-Size="9" BackColor="#fbfbfb" CustomRules="overflow: hidden;" />
                        <ClientSideEvents OnRowContextMenu="WebGrid1_OnRowContextMenu" OnRowSelect="OnRowSelect" OnAfterExitEditMode="WebGrid1_OnAfterExitEditMode" OnEditKeyDown="WebGrid1_OnEditKeyDown" OnRowValidate="WebGrid1_OnRowValidate" OnAfterResponseProcess="DisableCheck" OnKeyDown="WebGrid1_OnKeyDown" OnEnterEditMode="WebGrid1_OnEnterEditMode" />
                    </LayoutSettings>
                    <RootTable DataKeyField="Id" NewRowInfoText="เพิ่มรายการ">
                        <Columns>
                            <ISWebGrid:WebGridColumn IsRowChecker="true" Name="checker">
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Caption="Fund Center" Name="FundCenter" DataMember="FundCenter_FundCenterCode" Width="300px" EditType="WebComboNET" WebComboID="FundCenterCombo">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" BackColor="#a0a0a0" />
                                <ValueList DataTextField="Description" DataSourceID="FundCenterDataSource"
                                    DataValueField="FundCenter_FundCenterCode">
                                </ValueList>
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="Cmmt" Width="200px" Caption="รายการ" DataMember="CmmtCode" EditType="WebComboNET" WebComboID="CmmtCombo">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" BackColor="#a0a0a0" />
                                <ValueList DataTextField="Description" DataSourceID="CmmtDataSource"
                                    DataValueField="CmmtCode">
                                </ValueList>
                            </ISWebGrid:WebGridColumn>

                            <ISWebGrid:WebGridColumn Name="Product" Width="200px" Caption="ผลิตภัณฑ์" DataMember="ProductCode" EditType="WebComboNET" WebComboID="ProductCombo">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" BackColor="#a0a0a0" />
                                <ValueList DataTextField="Description" DataSourceID="ProductDataSource"
                                    DataValueField="ProductCode">
                                </ValueList>
                            </ISWebGrid:WebGridColumn>

                            <ISWebGrid:WebGridColumn Name="percen" Width="120px" DataMember="Element8" Caption="% ในการกระจาย" DataFormatString="##,##0.00" DefaultValue="0">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Right" />
                            </ISWebGrid:WebGridColumn>

                            <ISWebGrid:WebGridColumn Name="money" Width="120px" DataMember="Element9" Caption="วงเงิน" DataFormatString="##,##0.00" DefaultValue="0">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Right" />
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="budget" Width="120px" DataMember="Amount" Caption="งบประมาณ" DataFormatString="##,##0.00" DefaultValue="0">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Right" BackColor="#a0a0a0" />
                            </ISWebGrid:WebGridColumn>

                        </Columns>
                    </RootTable>

                </ISWebGrid:WebGrid>
                <ISWebCombo:WebCombo ID="FundCenterCombo" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="FundCenterCode" Height="20px" Width="200px" OnInitializeDataSource="FundCenterCombo_InitializeDataSource" AdditionalSearchFields="FundCenterCode" AllowWildCardSearch="true">
                    <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" EntryMode="AutoComplete" ComboMode="MultipleColumns">
                    </LayoutSettings>
                    <Columns>
                        <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ FundCenter" Width="250px" />
                        <ISWebCombo:WebComboColumn BaseFieldName="FundCenterCode" Name="FundCenterCode" HeaderText="รหัส FundCenter" Width="80px" />
                    </Columns>
                </ISWebCombo:WebCombo>
                <ISWebCombo:WebCombo ID="CmmtCombo" runat="server" UseDefaultStyle="true" DataTextField="Description" DataValueField="CmmtCode" OnInitializeDataSource="CmmtCombo_InitializeDataSource" AllowWildCardSearch="true">
                    <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" EntryMode="AutoComplete">
                    </LayoutSettings>
                </ISWebCombo:WebCombo>

                <ISWebCombo:WebCombo ID="ProductCombo" runat="server" UseDefaultStyle="true" DataTextField="Description" DataValueField="productCode" OnInitializeDataSource="Product_InitializeDataSource" AllowWildCardSearch="true">
                    <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" EntryMode="AutoComplete">
                    </LayoutSettings>

                </ISWebCombo:WebCombo>
                <div align="right">
                    <asp:Label ID="Label5" runat="server" Text="รวมจำนวนเงิน"></asp:Label>
                    <asp:TextBox ID="TextBox2" runat="server" Width="100px" ReadOnly="true" Style="text-align: center;"></asp:TextBox>
                </div>

            </div>
        </div>
    </div>
    <br />
    <br />
    <div style="display: none;">
        <ISWebTreeView:WebTreeView ID="WebTreeView1" runat="server" Height="265px" Width="235px" Visible="false">
            <NodeSettings EnableAnimation="True" />
        </ISWebTreeView:WebTreeView>
    </div>
    <div style="display: none;">
        <ISWebTreeView:WebTreeView ID="WebTreeView2" runat="server" Height="265px" Width="235px" Visible="false">
            <NodeSettings EnableAnimation="True" />
        </ISWebTreeView:WebTreeView>
    </div>
    <div style="display: none;">
        <ISWebTreeView:WebTreeView ID="WebTreeView3" runat="server" Height="265px" Width="235px" Visible="false">
            <NodeSettings EnableAnimation="True" />
        </ISWebTreeView:WebTreeView>
    </div>



    <asp:ObjectDataSource ID="FundCenterDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="BasicDataTableAdapters.FCTR_ValueTableAdapter">
        <SelectParameters>
            <asp:SessionParameter Name="PlanYear" SessionField="PlanYear" Type="Int16" />
        </SelectParameters>
    </asp:ObjectDataSource>

    <asp:ObjectDataSource ID="CmmtDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="MassChangeDSTableAdapters.CmmtsTableAdapter">
        <SelectParameters>
            <asp:SessionParameter Name="planyear" SessionField="PlanYear" Type="Int16" />
        </SelectParameters>
    </asp:ObjectDataSource>


    <asp:ObjectDataSource ID="ProductDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="MassChangeDSTableAdapters.ProductsTableAdapter">
        <SelectParameters>
            <asp:SessionParameter Name="planyear" SessionField="PlanYear" Type="Int16" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <script>
        function WebGrid_GetTotalRowCount() {

            try {

                var grid = ISGetObject("WebGrid1")
                if (grid == null || grid.RootTable == null) { alert(grid); return 0; }

                // NOTE: This is done because Intersoft doesn't return the TotalRows accurately for a WebGrid using BatchUpdate
                var rowCount = 0;
                while (true) {
                    var row = grid.RootTable.GetRow(rowCount)
                    if (row == null) { return rowCount; }
                    rowCount++;
                }
                //alert(rowCount);
            }
            catch (ex) {
                ShowJSException(ex);

            }
        }

        function DisableCheck() {
            try {
                var rowcount = WebGrid_GetTotalRowCount();
                var WebGrid1 = ISGetObject("WebGrid1");
                var rowCheckerElm = WebGrid1.RootTable.GetElement(WG40.COLHEADER, WG40.HTMLTABLE).cells[1].childNodes[0].childNodes[0].childNodes[0];

                if (rowcount == 0) {
                    rowCheckerElm.checked = false;
                    rowCheckerElm.disabled = true;


                    return true;
                } else {
                    rowCheckerElm.disabled = false;

                }
            } catch (err) { }
        }
        DisableCheck();
    </script>

    <%=AlertText %>
    <%=ScriptText %>
</asp:Content>


